<template>
  <div class="container" ref="mainCon">
    <el-row class="topSection">
      <el-row class="topBox">
        <div>
          <el-select
            v-model="projectId"
            filterable
            placeholder="请选择项目"
            @change="changeProject"
          >
            <el-option
              v-for="(item, index) of projectList"
              :key="index"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </div>
      </el-row>
    </el-row>
    <div class="mainCon">
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <div class="sub-title">
          ※
          待完善人员列表数据来源于工伤保险人员备案表，请根据备案信息完善人员基本信息以及合同信息。
        </div>
        <el-table
          ref="tableBox1"
          @sort-change="sortChange"
          :max-height="tableHeight"
          :data="tableList"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            prop="name"
            label="姓名"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="sex"
            label="性别"
            align="center"
            :formatter="formatTd"
            width="200px"
          ></el-table-column>
          <el-table-column
            prop="idcard"
            label="身份证号"
            align="center"
            :formatter="formatTd"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.idcard | deseHandler(4, 4, '*') || '--' }}</p>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="address" label="家庭地址" align="center" :formatter=formatTd width="220px"></el-table-column>  -->
          <el-table-column prop="address" label="家庭住址" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.address"
                :columnName="'address'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="tel"
            label="联系电话"
            align="center"
            :formatter="formatTd"
            min-width="120px"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.tel | deseHandler(3, 4, '*') || '--' }}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="startDate"
            sortable="custom"
            label="进工地时间"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column label="操作" align="left" width="110px">
            <template slot-scope="scope">
              <el-link type="primary" @click="improveEmployee(scope.row)"
                >补录信息</el-link
              >
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息" />
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getpageSize="getpageSize"
          @getpageNo="getpageNo"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        />
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'
export default {
  name: 'improveEmployeeList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '待完善人员列表',
      tableList: [],
      filterField: {
        projectId: '',
      },
      pageSize: 20,
      pageNo: 1,
      isShow: false,
      requestUrl: 'api-e/cs/consummate/expand/findConsummatePageByProjectId',
      loading: true,
      projectList: [],
      projectId: '',
    }
  },
  created() {
    this.getProjectList()
  },
  activated() {
    if (this.filterField.projectId) {
      this.$nextTick(function () {
        this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
      })
    }
  },
  methods: {
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },

    getProjectList() {
      this.axios({
        method: 'post',
        url: 'api-p/projectcompany/expand/current/projects',
      }).then(
        (response) => {
          if (!response.data.hasError) {
            this.projectList = response.data.result
            if (this.$route.query.projectId) {
              this.projectId = this.$route.query.projectId
              this.projectList.map((item, index) => {
                if (item.code === this.projectId) {
                  this.projectName = item.name
                }
              })
            } else {
              if (response.data.result.length > 0) {
                this.projectId = response.data.result[0].code
                this.filterField.projectId = this.projectId
              } else {
                this.projectId = '暂无关联项目'
                this.filterField.projectId = ''
              }
            }
            this.$refs.pagination.getTableListData()
          } else {
            this.projectId = '暂无关联项目'
            this.filterField.projectId = ''
            // this.projectId = "1";
          }
        },
        (response) => {
          this.projectId = '暂无关联项目'
        }
      )
    },
    changeProject(val) {
      this.filterField.projectId = val
      this.$refs.pagination.getTableListData()
    },
    improveEmployee(row) {
      this.$router.push({
        path: '/home/ESinsurance/improveEmployeeAdd',
        name: 'improveEmployeeAdd',
        query: {
          projectId: row.projectId,
          consummateId: row.id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/ESinsurance/improveEmployeeList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style scoped lang="less">
.saveBtn /deep/ .iconfont {
  padding: 0 5px;
  font-size: 14px;
}

@media screen and (min-width: 1280px) and (max-width: 1366px) {
  .searchInputWidth /deep/ .el-form-item__label {
    width: 70px;
  }
}
.mainCon {
  padding-top: 0;
}
.topSection {
  background: #fff;
  border-radius: 4px 4px 0 0;
  padding: 16px 24px 16px 10px;
  border-bottom: 1px solid #e3e7e9;
  .topBox {
    .projectState {
      display: inline-block;
      width: 60px;
      height: 20px;
      line-height: 20px;
      font-size: 12px;
      color: #fff;
      text-align: center;
      margin-left: 10px;
      font-weight: normal;
      margin-top: 5px;
    }
    /deep/.el-input__inner {
      width: 346px;
      font-size: 24px;
      font-weight: bold;
      color: #333333;
      border: none;
      height: 30px;
      // background: #E4EBF1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    /deep/.el-select__caret {
      color: #333;
      font-size: 20px;
      line-height: 30px;
    }
  }
  /deep/.commonTab {
    margin-top: 21px;
  }
  /deep/.is-active {
    background: #fff;
  }
}

.sub-title {
  font-size: 14px;
  color: #333333;
  height: 14px;
  line-height: 14px;
  margin-bottom: 14px;
}
</style>
